//时间轴转换成html-string日期
function timeformat(time,type){//日期,显示种类
	var	t = new Date(time*1000),
	Year 	= t.getFullYear(),
	Month 	= t.getMonth()+1,
	day 	= t.getDate();
	Hours   = t.getHours(),
	Minutes = t.getMinutes(),
	Seconds = t.getSeconds();
	if(Month<10)Month="0"+Month;
	if(day<10)day="0"+day;
	if(Hours<10)Hours="0"+Hours;
	if(Minutes<10)Minutes="0"+Minutes;
	if(Seconds<10)Seconds="0"+Seconds;
	switch (type) {
	case 0:
		return Year+"."+Month+"."+day+" "+Hours+":"+Minutes+":"+Seconds;
		break;
	case 1:
		return Year+"."+Month+"."+day;
		break;
	case 2:
	case "cn":
		return Year+"年"+Month+"月"+day+"日 "+Hours+":"+Minutes+":"+Seconds;
		break;
	case 3:
	case "cns":
		return Year+"年"+Month+"月"+day+"日 ";
		break;
	case 4:
		return Year+"年"+Month+"月"+day+"日 "+Hours+":"+Minutes;
		break;
	case 5:
		return Year+"-"+Month+"-"+day;
		break;
	case 6:
		return Month+"月"+day+"日 "+Hours+":"+Minutes;
		break;
	case 7:
		return Year+"-"+Month+"-"+day+" "+Hours+":"+Minutes;
		break;
	case 8:
		return Year+"/"+Month+"/"+day+" "+Hours+":"+Minutes;
		break;
	default:
		return Year+"."+Month+"."+day+" "+Hours+":"+Minutes+":"+Seconds;
		break;
	}
	return null;
}

//获取日期 //0:今天 1:明天 -1:昨天
function getDateString(AddDayCount) 
{ 
var dd = new Date(); 
dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期 
var y = dd.getFullYear(); 
var m = dd.getMonth()+1;//获取当前月份的日期 
var d = dd.getDate(); 
if(m<10)m="0"+m;
if(d<10)d="0"+d;
return y+"-"+m+"-"+d; 
} 

// 遍历是否在数组中 by vincent 20121124     
function isKeyFormArray(key,arr){
	for(var i=0;i<arr.length;i++){ 
		if(key==arr[i]) return true;
	}
	return false;
}

//将数组转换成带分隔符号的字符串
function array2string(arr,arg){
	var str = "";
	if(arr){
		var len = arr.length;
		for(var key in arr){
			str += arr[key];			
			if(key<len-1)
				str += arg;
		}
	}	
	return str;
}

//key:需要检验的值,type：检验类型[0:数字,1：普通值(不含非法字符),2:日期,3:中文,4:手机,5:金钱,6:电子邮箱]
function validate(key,type){
	if(type == null){ return false;}
	var number 	= /^[0-9]+$/,
		words 	= /^[0-9a-zA-Z.\-_]+$/,
		dat 	= /^[0-9-]+$/,
		chinese = /[\u4E00-\u9FA5]{2,5}(?:·[\u4E00-\u9FA5]{2,5})*/,
		mobile 	= /^[1-9]{1}\d{10}$|^\d{3,4}[-]\d{7,8}$/,//验证移动电话和固定电话两种类型
		money 	= /^[1-9]{1,}\d{0,}$|^\d{1,}[\.]\d{1,}/,
		email 	= /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	var patrn =new  Array(number,words,dat,chinese,mobile,money,email);
	if (!patrn[type].exec(key)) return false; 
	return true;
}

//截取字符串
function substring(str,len){
	if(!str)return str;
	if(!len) return str;
	var display = str.length<len ? "" : "...";
	return str.substr(0,len)+display; 
}

//是否数字 by vincent 201212007
function isDigit(s) 
{ 
var patrn=/^[0-9]+$/; 
if (!patrn.exec(s)) return false; 
return true ;
}

//查询浏览器
function checkBrowser(){
	var web=null;
	if($.browser.chrome){
		web = "chrome";
	}
	if($.browser.mozilla){
		web = "mozilla";
	}
	if($.browser.msie){
		web = "msie";
	}
	if($.browser.opera){
		web = "opera";
	}
	var bjson ={b:web,v:$.browser.version,s:$.support.style};
	return bjson;
}

/*判断输入值为数字*/
function input_num() {
	var a = event.keyCode;
	if (a > 58) {
		event.returnValue = false;
		alert("f");
	} else if (a < 48) {
		event.returnValue = false;
		alert("f");
	} else {
		event.returnValue = true;
		alert("t");
	}
}

function inputNum(arg) {
	arg.value = arg.value.replace(/[^\d]/g, '');
}

/*检查是否email格式*/
function checkEmail(name){
	var patrn = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	var value = ($("#"+name).val());
	if(!value)
		value = name;
	if (!patrn.exec(value)) {
		return false;
	} else {
		return true;
	}
}
/*检查是否手机号码*/
function checkNumber(name){
	var patrn = /^[0-9]+$/;
	var value = ($("#"+name).val());
	if (!patrn.exec(value)) {
		return false;
	} else {
		return true;
	}
}

/*检查数字*/
function checkNumber2(name,min,max){
	var patrn = /^[0-9]+$/;
	var value = ($("#"+name).val());
	var len =value.length;	
	if(len<min){
		return false;
	}
	if(len>max){
		return false;
	}	
	if (!patrn.exec(value)) {
		return false;
	} else {
		return true;
	}
}

//获取GET参数 vincent 20130111
function getUrlParam(name) {     
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象     
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数     
	if (r!=null) return unescape(r[2]); return null; //返回参数值
} 

//get_ajax
function G(json,callback,debug){
	$.ajax({  cache: false
        , type 		: "GET"
        , url 		: json.url
        , dataType 	: "json"
        , data 		: json       
        , error 	: function (XMLHttpRequest, textStatus, errorThrown) {
        	callback({code:0});
        	if(debug)
        		alertx(XMLHttpRequest.status,XMLHttpRequest.readyState,textStatus);        	
        }
        , success 	: function (data) {
        	if(debug)
        		alertjson(data);
        	callback(data);
          }     
	});
}

function GG(json,fn,debug){//20130715
	$.ajax({  cache: false
        , type 		: "GET"
        , url 		: json.requesturl
        , dataType 	: "json"
        , data 		: json       
        , error 	: function (XMLHttpRequest, textStatus, errorThrown) {
        	fn({code:0});
        	if(debug)
        		alertx(XMLHttpRequest.status,XMLHttpRequest.readyState,textStatus);        	
        }
        , success 	: function (data) {
        	if(debug)
        		alertjson(data);
        	fn(data);
          }     
	});
}
//ajax post
function P(json,callback,debug){
	$.ajax({  cache: false
        , type 		: "POST"
        , url 		: json.url
        , dataType 	: "json"
        , data 		: json       
        , error 	: function (XMLHttpRequest, textStatus, errorThrown) {
        	if(debug)
        		alertx(XMLHttpRequest.status,XMLHttpRequest.readyState,textStatus);        	
        }
        , success 	: function (data) {
        	if(debug)
        		alertjson(data);
        	callback(data);
          }     
	});
}

function alertjson(json){//打印多个参数 20130615 by vincent
	var str = "";
	$.each(json, function(index, value) {
		str += index+'：'+value+'\n';
		});
	alert(str);
}

function json2array(json){
	var obj = {key:[],value:[]};
	$.each(json, function(index, value) {
		obj.key.push(index);
		obj.value.push(value);
		});
	//alertx(obj.key,obj.value);
	return obj;
}
